﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using TimKen.BussLogic;
using TimKen.DataEntity;
using TimKen.App;


namespace TimKen.Web.UserControls
{
    public partial class DropDownCategoryList :BaseUserControl
    {
        private PCategoryManager categoryManager = new PCategoryManager();
        private string toadd = "├";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.ddlCategory.Items.Clear();
                this.ddlCategory.Items.Add(new ListItem(GetLangString("SetAsRootCategory"), "0"));
                BindProductCategory("0");
            }
        }

        public int CategoryID 
        {
            get
            {
                return Convert.ToInt32(this.ddlCategory.SelectedValue);
            }
        }
        /// <summary>
        /// 绑定产品分类分级选择列表
        /// </summary>
        private void BindProductCategory(string parentId)
        {
            DataSet ds = categoryManager.GetList(LanguageWhereStr + " AND ParentID=" + parentId);

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    this.ddlCategory.Items.Add(new ListItem(toadd + " " + dr["CategoryName"].ToString(), dr["CategoryID"].ToString()));
                    toadd += "─┴";
                    BindProductCategory(dr["CategoryID"].ToString());
                    toadd = toadd.Substring(0, toadd.Length - 2);
                }
            }
        }

    }
}